<template>
  <div>

    <div class="goods-list">

      <div class="goods-item" v-for="item in goodList" :key="item.id" @click="getDetail(item.id)">
        <img :src="item.img_url" alt="">
        <h1 class="title" v-text="item.title"></h1>
        <div class="info"> 
          <p class="price">
            <span class="new">￥{{ item.sell_price }}</span>
            <span class="old"><del>￥{{ item.market_price }}</del></span>
          </p>
          <p class="sell">
            <span>热卖中</span>
            <span>剩余{{ item.stock_quantity }}件</span>
          </p>
        </div>
      </div>

    </div>

    <mt-button type="danger" size="large" @click="getMore">加载更多</mt-button>

  </div>
</template>
<script>
    export default {
      data() {
        return {
          pageindex: 1,
          goodList: []
        }
      },
      created() {
        this.getGoodList();
      },
      methods: {
        getGoodList() {
          this.$http.get("api/getgoods?pageindex="+this.pageindex).then(result=>{
            if(result.body.status === 0) {
              // console.log(result.body);
              // this.goodList = result.body.message;
              this.goodList = this.goodList.concat(result.body.message);
            }
          })
        },
        getMore() {
          this.pageindex ++;
          this.getGoodList();
        },
        getDetail(id) {

          //this.$router 路由导航对象
          this.$router.push("/home/goodsInfo/"+ id);
        }
      }
    }
</script>
<style lang="scss" scoped>
.goods-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  padding: 6px;
  .goods-item {
    width: 49%;
    border: 1px solid #ccc;
    box-shadow: 0 0 6px #ccc;
    margin: 3px 0;
    padding: 2px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    img {
      width: 100%;
    }
    .title {
      font-size: 14px;
    }

    .info {
      background-color: #eee;
      p{
        margin: 0;
        padding: 5px 0;
      }
      .price {
        .old {
          font-size: 14px;
          font-style: italic;
          margin-left: 10px;
        }
        .new {
          color: red;
          font-weight: bold;
          font-size: 16px;
        }
      }
      .sell {
        display: flex;
        justify-content: space-between;
        font-size: 13px;
      }
    }
  }
}


</style>
